<?php
/**
 * RedXenon Framework
 * 
 * LICENSE
 * 
 * This source file is subject to the New BSD license that is bundled
 * with this package in the file LICENSE.txt
 * A copy of this license can be found in the world-wide-web at this URL:
 * http://www.redxenon.com/license/new-bsd-license.txt * 
 */

/* Abstract class */
require_once("RXAbstractFormElement.php");

/**
 * RedXenon Form (RXInput.php)
 * Defines methods to create Input elements
 * 
 * @category RedXenon
 * @package RedXenon_Input
 * @copyright Copyright (c) 2011 Red Xenon (http://www.redxenon.com)
 * @version $Id: RXInput.php 1.0 2011-05-02 $ 
 */
class RXInput extends RXAbstractFormElement{

	/**
	 * Input type
	 * @var String
	 */
	private $type;
	
	/**
	 * CSS class
	 * @var String
	 */
	private $class;

	/**
	 * Input size
	 * @var Integer
	 */
	private $size;
	
	/**
	 * Field maxlength
	 * @var Integer
	 */
	private $maxlength;
	
	/**
	 * Input value
	 * @param String
	 */
	private $value;
	
	/**
	 * Creates an instance of a Form Input object
	 * @param String $type
	 * @param String $value
	 * @param Integer $size
	 * @param Integer $maxlength
	 * @param String $class
	 */
	public function __construct(	$name = NULL,													
													$type = "text",
													$value = NULL, 
													$size = NULL, 
													$maxlength= NULL, 
													$class = NULL, 
													$id = NULL){
		$this->type = $type;
		$this->value = $value;
		$this->size = $size;
		$this->maxlength = $maxlength;
		$this->class = $class;
		parent::__construct($name);
	}
	
	/**
	 * Sets the input field to a text field
	 */
	public function setTypeText(){
		$this->type = "text";
	}
	
	/**
	 * Sets the input field to a password field
	 */
	public function setTypePassword(){
		$this->type = "password";
	}
	
	/**
	 * Sets the input field to a submit button
	 */
	public function setTypeSubmit(){
		$this->type = "submit";
	}
	
	/**
	 * Sets the input field as a file upload field
	 */
	public function setTypeFile(){
		$this->type = "file";
	}
	
	/**
	 * Sets the field value
	 * @param String $value
	 */
	public function setValue($value){
		$this->value = $value;
	}
	
	/**
	 * Sets the field size
	 * @param Integer $size
	 */
	public function setSize($size){
		$this->size = $size;
	}
	
	/**
	 * Sets the field max length
	 * @param String $maxlength
	 */
	public function setMaxLength($maxlength){
		$this->maxlength = $maxlength;
	}
	
	/**
	 * Returns the HTML code for the input field
	 * @return String
	 */
	public function getOutput(){
		$ret = '<input type="'.$this->type.'"';

		if(isset($this->name))
			$ret .= ' name="'.$this->name.'"';
		if(isset($this->id))
			$ret .= ' id="'.$this->id.'"';
		if(isset($this->class))
			$ret .= ' class="'.$this->class.'"';
		if(isset($this->size))
			$ret .= ' size="'.$this->size."'";
		if(isset($this->maxlength))
			$ret .= ' maxlength="'.$this->maxlength."'";
		if(isset($this->value))
			$ret .= ' value="'.$this->value."'";
		if($this->isHidden)
			$ret .= ' hidden';
		
		$ret .= '/>';
		return $ret;
	}
}
?>